<template>
  <div>
    <!--    搜索栏-->
    <el-row class="table-grid-content">
      <el-col :span="24" class="grid">
        <el-input v-model="input" placeholder="请输入搜索关键字"></el-input>
      </el-col>
    </el-row>
    <!--    头部命名-->
    <el-table
      :data="table"
      border
      style="width: 100%"
      max-height="540px">
      <el-table-column
        align="center"
        prop="usersName"
        label="姓名">
      </el-table-column>
      <el-table-column
        align="center"
        prop="userMajor"
        label="专业">
      </el-table-column>
      <el-table-column
        align="center"
        prop="userClass"
        label="班级">
      </el-table-column>
      <el-table-column
        align="center"
        prop="usersId"
        label="学号">
      </el-table-column>
      <el-table-column
        align="center"
        prop="addCause"
        label="加分原因">
      </el-table-column>
      <el-table-column
        align="center"
        prop="addScore"
        label="加分分数">
      </el-table-column>
      <el-table-column
        align="center"
        prop="addType"
        label="加分类型">
      </el-table-column>
      <el-table-column
        align="center"
        prop="addTime"
        label="日期">
      </el-table-column>
      <el-table-column
        align="center"
        label="操作">

        <template slot-scope="scope">
          <el-button type="primary" @click="amend(scope.row)">修改</el-button>
        </template>

      </el-table-column>
    </el-table>

    <!--    修改弹窗-->
    <el-dialog
      title="修改"
      :visible.sync="dialogVisible"

      width="30%"
      :append-to-body="true">

      <el-form :model="user" label-width="80px">
        <el-form-item label="姓名">
          <el-input v-model="user.usersName"></el-input>
        </el-form-item>

        <el-form-item label="专业">
          <el-input v-model="user.userMajor"></el-input>
        </el-form-item>

        <el-form-item label="班级">
          <el-input v-model="user.userClass"></el-input>
        </el-form-item>

        <el-form-item label="学号">
          <el-input v-model="user.usersId"></el-input>
        </el-form-item>

        <el-form-item label="加分原因">
          <el-input v-model="user.addCause"></el-input>
        </el-form-item>

        <el-form-item label="加分分数">
          <el-input v-model="user.addScore"></el-input>
        </el-form-item>

        <el-form-item label="加分类型">
          <el-input v-model="user.addType"></el-input>
        </el-form-item>
        <el-button type="primary" @click="onSubmit"
                   style="
                   position: relative;
                   left: 50%;
                   transform: translateX(-50%);"
        >确定修改</el-button>
      </el-form>
    </el-dialog>

    <!--  分页功能  -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount">
    </el-pagination>
  </div>
</template>

<style scoped>
.table-grid-content {
  border-radius: 8px;
  height: 50px;
  background: #ebeef5;
  padding: 5px;
  margin: 0;
}
</style>

<script>
import axios from "axios";

export default {
  name: 'AwardedMarksDisplay',

  mounted() {
    //页面加载完成后异步请求查询所有数据
    this.selectAll();
  },

  methods: {
    //修改获取数据
    amend(row){
      this.dialogVisible = true;
      this.user = row;
      console.log(this.user)
    },

    //查询所有函数
    selectAll() {
      axios.get('/api/marks/announced-page?currentPage=' + this.currentPage + "&pageSize=" + this.pageSize).then((res) => {

        console.log(res.data.data.dataList)
        //设置表格数据
        this.tables = res.data.data.dataList;

        //设置总记录数
        this.totalCount = res.data.data.pageTotal;
      })
    },

    //修改上传
    onSubmit() {
      console.log("submit")
    },

    //分页功能
    handleSizeChange(val) {
      //重新设置每页显示的条数
      this.pageSize = val;
      this.selectAll();
    },
    handleCurrentChange(val) {
      //重新设置当前页码
      this.currentPage = val;
      this.selectAll();
    },

    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    goBack() {
      console.log('go back');
    },
  },
  computed: {

    // 搜索框
    table() {
      const input = this.input
      if (input) {
        return this.tables.filter(data => {
          return Object.keys(data).some(key => {
            return String(data[key]).toLowerCase().indexOf(input) > -1
          })
        })
      }
      return this.tables
    }
  },
  data() {
    return {
      //分页
      //当前页码
      currentPage: 1,
      //每页显示条数
      pageSize: 10,
      //总记录数
      totalCount: 100,

      //表格数据
      tables:[],

      dialogVisible: false,  //修改按钮

      //搜索框
      msg: 'Welcome to Your Vue.js App',
      centerDialogVisible: false,
      isAddMembers: false,
      searchData: '',
      input: '',
      id: '',

      //修改数据
      user: {},

    }
  }
}
</script>

